﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace game
{
    public class Blaster : Weapon
    {
        public BlasterCell.Color Color { get; protected set; }

        public Blaster(Scene scene, Ship shooter, BlasterCell.Color color)
            : base(scene, shooter)
        {
            Color = color;
            shotIntervalMs = 120;
            loadSpeed = 0.0004f;
            shotLoadCost = 0.16f;
        }

        bool left = true;

        public override bool Shoot(int layerIndex, Vector3 position, Vector3 rotation, Vector3 velocity)
        {
            if (!CanShoot())
            {
                return false;
            }

            Vector3 offset = -300.0f * Vector3.Transform(
                    Vector3.Forward, Matrix.CreateRotationY(rotation.Y));

            position += offset;

            Vector3 movement = Vector3.Transform(new Vector3(1200, 0, 0), Matrix.CreateRotationZ(rotation.Z));
            movement = Vector3.Transform(movement, Matrix.CreateRotationY(rotation.Y));

            Projectile p;
            //if (left)
            {
                p = new BlasterCell(scene, shooter, layerIndex, position - movement - offset, rotation, Color);
                p.InitialVelocity = velocity;

                scene.AddObject(
                    p, layerIndex);

                
            }
            //else
            {
                p = new BlasterCell(scene, shooter, layerIndex, position + movement - offset, rotation, Color);
            }
            p.InitialVelocity = velocity;

            scene.AddObject(
                p, layerIndex);

            scene.BilboardMgr.BlasterShot(position - movement, velocity, Color);
            scene.BilboardMgr.BlasterShot(position + movement, velocity, Color);

            left = !left;

            scene.SoundMgr.Blaster(position);

            ShootUpdate();
            ProjectileQuantity -= 1; // additional subtraction, since blaster uses to rounds per shot

            return true;
        }
    }
}
